<template>
    <!-- 供应商库列表 -->
    <div class="e-table billList">
        <div class="top">
            <div class="left" style="margin-left: 10px">
                <div>
                    <el-button
                        @click="buttonAdd()"
                        style="background: #7aa818; color: #fff"
                        >新增</el-button
                    >
                </div>
            </div>
            <div class="right">
                <el-button-group style="margin-right: 5px">
                    <el-button
                        :class="selActive === 'all' ? 'like' : ''"
                        @click="getData"
                        >全部</el-button
                    >
                    <el-button
                        :class="selActive === 'qualified' ? 'like' : ''"
                        @click="qualified"
                        >合格供应商</el-button
                    >
                    <el-button
                        :class="selActive === 'NoQualified' ? 'like' : ''"
                        @click="NoQualified"
                        >不合格供应商</el-button
                    >
                    <el-button
                        :class="selActive === 'blacklist' ? 'like' : ''"
                        @click="blacklist"
                        >黑名单</el-button
                    >
                </el-button-group>
                <div>
                    <el-input
                        placeholder=""
                        v-model="advancedQuery.keyword"
                        @keyup.enter.native="getData"
                    >
                        <i
                            slot="suffix"
                            style="cursor: pointer"
                            @click="getData"
                            class="el-icon-search"
                        ></i>
                    </el-input>
                </div>
                <div>
                    <el-button
                        size="small"
                        style="
                            background: #2e61d7;
                            color: #fff;
                            margin-left: 5px;
                        "
                        @click="onAdvanceSearch"
                        >高级搜索</el-button
                    >
                </div>
            </div>
        </div>

        <el-table
            v-loading="loading"
            border
            ref="table"
            :data="tableData"
            tooltip-effect="dark"
            class="table"
            style="width: 100%"
            algin="left"
            highlight-current-row
            height="0"
            @selection-change="handleSelectionChange"
            @cell-mouse-enter="cellMouseEnter"
            @cell-mouse-leave="cellMouseLeave"
            v-sortTable="{ tableData: tableData, _this: this, ref: 'table' }"
        >
            <el-table-column
                label="供应商名称"
                fixed="left"
                align="left"
                min-width="200"
            >
                <template slot-scope="scope">
                    <span
                        @click="Examine(scope.row)"
                        style="color: blue; cursor: pointer"
                    >
                        {{ scope.row.supplierName }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column
                prop="creditCode"
                label="统一社会信用代码"
                min-width="200"
                fixed="left"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="registerCapital"
                label="注册资本（万元）"
                width="150"
            >
            </el-table-column>
            <el-table-column
                prop="manageOrgName"
                label="管理单位"
                width="250"
                align="left"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="supplierCommodityName"
                label="供应商品"
                width="150"
                align="left"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="qualificationLevelName"
                label="资质等级"
                width="250"
                align="left"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column prop="creditLevel" label="信用等级" width="100">
                <template slot-scope="scope">
                    {{
                        scope.row.creditLevel == '0'
                            ? '待定'
                            : scope.row.creditLevel == '1'
                            ? 'A'
                            : scope.row.creditLevel == '2'
                            ? 'B'
                            : scope.row.creditLevel == '3'
                            ? 'C'
                            : scope.row.creditLevel == '4'
                            ? 'D'
                            : scope.row.creditLevel == '5'
                            ? 'S'
                            : ''
                    }}
                </template>
            </el-table-column>
            <el-table-column
                prop="supplierTypeKey"
                label="类型"
                width="150"
                align="left"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="state"
                label="状态"
                width="100"
                show-overflow-tooltip
            >
                <template slot-scope="scope">
                    <ToolHistory
                        v-if="scope.row.state === 1"
                        :key="scope.$index"
                        url="/outer/audit/getAuditHistory"
                        :billId="scope.row.id"
                        :billType="6041"
                    >
                        <span v-status="scope.row.state">
                            {{ statusLable(scope.row.state) }}
                        </span>
                    </ToolHistory>
                    <span v-else v-status="scope.row.state">
                        {{ statusLable(scope.row.state) }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column prop="changeState" label="变更状态" width="100">
                <template slot-scope="scope">
                    <ToolHistory
                        v-if="scope.row.changeState === 1"
                        :key="scope.$index"
                        url="/outer/audit/getAuditHistory"
                        :billId="scope.row.sourceId"
                        :billType="604101"
                    >
                        <span v-status="scope.row.changeState">
                            {{ statusLable(scope.row.changeState) }}
                        </span>
                    </ToolHistory>
                    <span v-else v-status="scope.row.changeState">
                        {{ statusLable(scope.row.changeState) }}
                    </span>
                </template>
            </el-table-column>
        </el-table>

        <ComPagination
            :total="totalCount"
            :pageSize.sync="advancedQuery.limit"
            :currentPage.sync="advancedQuery.page"
            @currentChange="currentChange"
            @sizeChange="sizeChange"
        />
    </div>
</template>
<script>
import ComPagination from '@/components/pagination/pagination.vue'
//审核
import examine from '@/api/OutsourcingartyAdmin/subcontractorAdmin/examine.js'
import { advanceSearch } from '@/utils/common.js'
import { mapMutations } from 'vuex'

export default {
    components: {
        ComPagination
    },
    data () {
        return {
            selActive: '', //动态class样式
            isBatch: false, //是否进入批量操作
            batch: '进入批量管理',
            dialogVisibleSearch: false,
            searchIpt: '',
            input1: '',
            value1: '',
            value2: '',
            tableData: [
                {
                    supplierName: '', //供应商名称
                    registerCapital: '', //注册资本
                    creditCode: '', //统一社会信用代码
                    manageOrgName: '', //管理单位
                    supplierCommodityName: '', //供应商品
                    qualificationLevelName: '', //资质等级
                    creditLevel: '', //信用等级
                    state: '', //状态
                    theStatus: '' //变更状态
                }
            ],
            loading: true,
            MouseEnterId: 0,
            // 初始化列表数据
            totalCount: 0, //总页数
            advancedQuery: {
                outerType: [], //供应商类型
                creditCode: '', //统一社会信用代码
                creditGrade: [], //信用等级
                qualificationLevel: [], //供应商品
                grade: [], //资质等级
                states: [], //单据状态
                orgId: '', //单据机构
                manageOrg: [], //管理单位
                startCapital: null, //开始注册资本
                endCapital: null, //结束注册资本
                isAbroadUnit: null, //境外单位
                keyword: '', //	模糊查询关键字
                limit: 20, //每页显示条数
                page: 1 //当前页数
            }
        }
    },
    created () {
        this.getData()
    },
    computed: {
        // 判断状态
        statusLable () {
            return param => {
                const state = this.$store.state.equip.equipData.state
                const obj = state.find(x => x.value == param)
                if (obj !== undefined) {
                    return obj.label
                }
            }
        }
    },
    methods: {
        ...mapMutations(['setSelectedInfo']),
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        //查询供应商列表数据
        getData () {
            this.loading = true
            this.selActive = 'all'
            this.$Ajax
                .httpPost({
                    url: '/outer/supplier/listByEntity',
                    params: this.advancedQuery
                })
                .then(res => {
                    this.totalCount = res.totalCount
                    this.tableData = res.list
                    setTimeout(() => {
                        this.loading = false
                    }, 500)
                })
        },
        //新增按钮
        buttonAdd () {
            this.$router.push('/supplierbePutinstorageAdd')
        },

        handleSelectionChange (val) {
            this.multipleSelection = val
        },
        //查看
        Examine (row) {
            //点击进入查看页面
            const billid = row.id
            if (row.state === -1 || row.state === 2 || row.state === 5) {
                this.$router.push({
                    path: '/supplierbePutinstorageExamine',
                    query: { billid }
                })
            } else {
                // 根据按钮状态来判断点击编辑进什么页面
                examine
                    .getCurrentUnitInfo({
                        billId: billid,
                        billType: 6041,
                        freeNextUnitIndex: 0,
                        freeNextUser: '',
                        isPass: true,
                        isShareInAudit: true,
                        opinion: ''
                    })
                    .then(res => {
                        this.auditState = res
                        if (this.auditState.canModify) {
                            this.$router.push({
                                path: '/supplierbePutinstorageEdit',
                                query: { billid }
                            })
                        } else {
                            this.$router.push({
                                path: '/supplierbePutinstorageExamine',
                                query: { billid }
                            })
                        }
                    })
            }
        },
        //点击表格编辑
        tableDbEdit (billid) {
            this.$router.push({
                path: '/supplierbePutinstorageEdit',
                query: { billid }
            })
        },
        //合格
        qualified () {
            this.selActive = 'qualified'
            this.loading = true
            this.$Ajax
                .httpPost({
                    url: '/outer/supplier/listByQualifiedEntity',
                    params: {
                        creditcode: '',
                        keyword: '',
                        limit: 20,
                        number: '',
                        page: 1,
                        subcontractorname: ''
                    }
                })
                .then(res => {
                    this.tableData = res.list
                    this.totalCount = res.totalCount
                    setTimeout(() => {
                        this.loading = false
                    }, 500)
                })
        },
        //不合格
        NoQualified () {
            this.selActive = 'NoQualified'
            this.loading = true
            this.$Ajax
                .httpPost({
                    url: '/outer/supplier/listByUnqualifiedEntity',
                    params: {
                        creditcode: '',
                        keyword: '',
                        limit: 20,
                        number: '',
                        page: 1,
                        subcontractorname: ''
                    }
                })
                .then(res => {
                    this.tableData = res.list
                    this.totalCount = res.totalCount
                    setTimeout(() => {
                        this.loading = false
                    }, 500)
                })
        },
        //黑名单
        blacklist () {
            this.selActive = 'blacklist'
            this.loading = true
            this.$Ajax
                .httpPost({
                    url: '/outer/supplier/listByBlackEntity',
                    params: {
                        creditcode: '',
                        keyword: '',
                        limit: 10,
                        number: '',
                        page: 1,
                        subcontractorname: ''
                    }
                })
                .then(res => {
                    this.tableData = res.list
                    this.totalCount = res.totalCount
                    setTimeout(() => {
                        this.loading = false
                    }, 500)
                })
        },
        //翻页
        currentChange () {
            if ( this.selActive == 'all') {
                this.getData()
            }else if( this.selActive == 'qualified') {
                this.qualified()
            }else if( this.selActive == 'NoQualified') {
                this.NoQualified()
            }else{
                this.blacklist()
            }
        },
        //改变条数
        sizeChange () {
            if ( this.selActive == 'all') {
                this.getData()
            }else if( this.selActive == 'qualified') {
                this.qualified()
            }else if( this.selActive == 'NoQualified') {
                this.NoQualified()
            }else{
                this.blacklist()
            }
        },
        //高级查询
        onAdvanceSearch () {
            advanceSearch('/subcontractorSearch?type=2').then(res => {
                this.advancedQuery.outerType = res.subcontractorTypeValue //外包方类型
                this.advancedQuery.creditCode = res.creditCode //信用代码
                this.advancedQuery.grade = res.grade //资质等级
                this.advancedQuery.isAbroadUnit = res.isAbroadUnit //境外单位
                this.advancedQuery.creditGrade = res.creditLevelTypeKey //信用等级
                this.advancedQuery.states = res.stateTypeKey //状态
                this.advancedQuery.startCapital = res.startCapital //开始资本
                this.advancedQuery.endCapital = res.endCapital //结束资本
                this.advancedQuery.manageOrg = res.manageOrg //管理单位
                this.advancedQuery.supplierName = res.subcontractorName //分包商名称
                this.advancedQuery.qualificationLevel = res.main //供应商品
                this.getData()
            })
        }
    }
}
</script>
<style lang="scss" scoped>
.like {
    background-color: #409eff;
    color: white;
}
.e-table ::v-deep.el-table__cell.is-left {
    text-align: left;
}
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
    width: 6px; // 横向滚动条
    height: 10px; // 纵向滚动条
}
// 滚动条的滑块
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 5px;
}
::v-deep .el-button:focus,
.el-button:hover {
    background-color: #409eff;
    color: white;
}
</style>
